<template>
  <div>
    <van-nav-bar title="账号登陆" left-arrow />
    <van-form @submit="onSubmit">
      <van-field
        v-model="model.username"
        name="用户名"
        placeholder="请输入账号"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="model.password"
        type="password"
        name="密码"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button
          round
          block
          type="info"
          native-type="submit"
          square
          color="#21b97a"
           :loading="isLoding"
            :disabled="isLoding"
          >提交</van-button
        >
        <p  style="fontSize=.3rem;text-align: center ">还没有账号，去注册~</p>
      </div>
    </van-form>
  </div>
</template>

<script>
import { LoginApi } from '@/api'
import { Notify } from 'vant'
export default {
  data () {
    return {
      model: {
        username: 'hzhmqd',
        password: '123456'
      },
      isLoding: false
    }
  },
  methods: {
    async onSubmit () {
      this.isLoding = true
      try {
        const res = await LoginApi(this.model)
        console.log(res)
        this.isLoding = false
        Notify({ type: 'success', message: '登录成功' })
        this.$router.replace('/layout')
      } catch (error) {
        console.log(error)
        this.isLoding = false
        Notify({ type: 'success', message: '登录失败' })
      }
    }
  }
}
</script>

<style>

</style>
